package com.yanze.schoolinformation.viewModule.person;

import com.yanze.schoolinformation.app.C;
import com.yanze.schoolinformation.model.bean.resp.RespUser;
import com.yanze.schoolinformation.model.http.DeforObserver;
import com.yanze.schoolinformation.model.http.reqo.DataReqo;
import com.yanze.schoolinformation.view.my.person.ModifyActivity;
import com.yanze.schoolinformation.view.my.person.PersonActivity;

import io.reactivex.disposables.Disposable;

/**
 * Created by MrZheng on 2018/5/8.
 */

public class ModifyViewModel {

    private ModifyActivity mActivity;
    private ModifyNavigator mNavigator;

    public ModifyViewModel(ModifyActivity mActivity) {
        this.mActivity = mActivity;
    }

    public void setmNavigator(ModifyNavigator mNavigator) {
        this.mNavigator = mNavigator;
    }

    public void modifyUserInfo(String userid, String nickname, String userqq, String userwechat) {
        DataReqo.getInstant().modify(C.url.API_School, userid, nickname, userqq, userwechat)
                .subscribe(new DeforObserver<RespUser>() {
                    @Override
                    public void _onSubscribe(Disposable disposable) {
                        mActivity.addSubscription(disposable);
                    }

                    @Override
                    public void _onNext(RespUser entity) {
                        if (entity.getStatus() == 200) {
                            mNavigator.uploadSuccess(entity);
                        }else{
                            mNavigator.uploadFail(entity.getMsg());
                        }
                    }

                    @Override
                    public void _onError(String msg) {
                        mNavigator.uploadFail(msg);
                    }
                });
    }

    public void onDestory() {
        mActivity = null;
        mNavigator = null;
    }
}
